<?php

/**
 * 微博抓取管理
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/mblog/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/tuijian/inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/qq/inc.php");
$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
		//页码
	cgi::get($g_cgival["p"], "p", 1);
	$g_cgival["p"] = intval($g_cgival["p"]);

	cgi::get($g_cgival["type"], "type", 0);
	$g_cgival["type"] = intval($g_cgival["type"]);
	
	cgi::get($g_cgival["topic_id"], "topic_id", 0);
	$g_cgival["topic_id"] = intval($g_cgival["topic_id"]);
	
	
	cgi::get($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = string::un_html($g_cgival["uid"]);
	
	cgi::get($g_cgival["key"], "key", "");
	$g_cgival["key"] = string::un_html($g_cgival["key"]);
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	$pcount = 20;
	$start = ($g_cgival["p"] - 1)*$pcount;
	
	$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
	$topic_id = $g_show["topic_id"] = $g_cgival["topic_id"] ;
	$g_show["uid"] = $g_cgival["uid"] ;
	$g_show["key"] = $g_cgival["key"] ;
	$db_mblog_pic_content = new db_mblog_pic_content();
	
	if($g_cgival["key"] && $topic_id && $g_cgival["uid"] )
	{
		
		$mblog_from_api = new mblog_from_api();
		$mblog_list  = $mblog_from_api->api_get_mblog_by_uids_and_search($g_cgival["key"],$g_cgival["uid"],$start,$pcount,$isred=false,$zone="",$startime="",$endtime="",
		$hasori=1,
		$hasret="",
		$hastext="",
		$haspic=1);
		
		$count = $mblog_list["data"]["count"];
		
		$mids = array();
		$total_count = $mblog_list["data"]["count"];
		foreach( $mblog_list["data"]["result"] as $key => $value)
		{
			$mids[]  = $value["mid62"];
		}
		$mids = join(",",$mids);
		
		
		if(!$mids)
		{
			return false;
		}
		$mblog_list = $mblog_from_api->api_get_mblog_by_mids($mids,$trim_user=0);
		$mblog_list["data"]["result"] = array_values($mblog_list["data"]["result"]);
	
		
		foreach($mblog_list["data"]["result"] as $key => $value)
		{
			$get_count = $db_mblog_pic_content->cron_get_count_by_mid($value["idstr"]);
			if($get_count>0)
			{
				$mblog_list["data"]["result"][$key]["have_get"] = 1;
			}
			else
			{
				$mblog_list["data"]["result"][$key]["have_get"] = 0;
			}
		}
		
		$g_show["count"] = $count;
		$g_show["list"] = $mblog_list["data"]["result"];
		
		
		$max_page = page_bar::get_page_max($g_show["count"], $pcount, $g_cgival["p"]);
		$page_bar_style = array(
				"curt"		=> $g_cgival["p"],
				"max"		=> $max_page,
				"key"		=> "p",
		);
		$g_show["page_bar"] = "<b>{$count}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar3($page_bar_style);
	
		
		$topic_tag_list = $db_mblog_cron_topic_tag->admin_get_mblog_cron_topic_tag_list_by_search(1,100,"","",$topic_id);
		
		$g_show["topic_tag_list"] = $topic_tag_list;
	}

	
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	$smarty->display ( "mblog/get_mblog_by_search_uid.html" );
}

